package com.help.help.service.impl;

import com.help.help.entity.AddressEntity;
import com.help.help.service.UserService;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import com.help.help.dao.ApproveDao;
import com.help.help.entity.ApproveEntity;
import com.help.help.service.ApproveService;


@Service("approveService")
public class ApproveServiceImpl extends ServiceImpl<ApproveDao, ApproveEntity> implements ApproveService {
   @Autowired
   private UserService userService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<ApproveEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if(!StringUtil.isNullOrEmpty(key)){
            wrapper.eq("name",key).or().eq("card_num",key).or().eq("user_id",key);
        }
        IPage<ApproveEntity> page = this.page(
                new Query<ApproveEntity>().getPage(params),
                wrapper
        );
        List<ApproveEntity> records = page.getRecords();
        for (ApproveEntity record : records) {
            if(record.getUserId()!=null){
                record.setUser(userService.getById(record.getUserId()));
            }
        }

        return new PageUtils(page);
    }

}